<?php

declare(strict_types=1);

namespace App\Exception;


use App\Constants\CodeData;
use Hyperf\Context\Context;
use Hyperf\Server\Exception\ServerException;
use Throwable;
use function Hyperf\Translation\trans;

class MessageException extends ServerException
{
    protected mixed $data;

    public function __construct(string $message = "", int $code = CodeData::NEED_TIPS, mixed $data = [], $trans = true, Throwable $previous = null)
    {
        $language = Context::get('language', 'en');
        if ($trans) {
            $message = trans("desc." . $message, [], $language);
        }
        parent::__construct($message, $code, $previous);
        $this->data = $data;
    }

    public function getData()
    {
        return $this->data;
    }
}